package cn.xs.tool.demo.somiao;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import cn.xs.tool.demo.somiao.scan.CaptureActivity;
import zxing.decoding.BaseCaptureActivity;

public class MainActivity extends Activity {

	private Button btn_scan;
	private TextView tv_scan;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		btn_scan = (Button) findViewById(R.id.btn_scan);
		tv_scan = (TextView) findViewById(R.id.tv_scan);
		btn_scan.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				tv_scan.setText("");
				Intent intent = new Intent(MainActivity.this,
						CaptureActivity.class);
				startActivityForResult(intent, 0);
			}
		});
		findViewById(R.id.btn_scan2).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				tv_scan.setText("");
				Intent intent = new Intent(MainActivity.this,
						BaseCaptureActivity.class);
				startActivityForResult(intent, 0);
			}
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		String barcode = data.getStringExtra("SCAN_RESULT");

		if ("".equals(barcode) || barcode == null) {

		} else {

			tv_scan.setText(barcode);

		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
